// pages/myorder/myorder.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tips: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    if (app.globalData.userInfo.nickName == '' || app.globalData.userInfo.nickName == undefined || app.globalData.userInfo.nickName == '请点击头像登录') {
      this.setData({
        tips: "请登录之后查看订单",
      })
      return false;
    }
    wx.request({
      url: 'https://orders.linshiqiang.cn/api/order/myorder?user_name=' + app.globalData.userInfo.nickName,
      success(res) {
        // console.log(res)
        let orderList = res.data.data.orderResult
        
        console.log(orderList)

  
        // 时间戳转换
        for (let i = 0; i < orderList.length; i++) {
          let date = new Date(orderList[i].pay_time * 1000);
          let year = date.getFullYear();
          let month = (date.getMonth() + 1).toString().padStart(2, '0');
          let day = date.getDate().toString().padStart(2, '0');
          let hour = date.getHours().toString().padStart(2, '0');
          let minute = date.getMinutes().toString().padStart(2, '0');
          let second = date.getSeconds().toString().padStart(2, '0');
          let ymdtime = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second
          // console.log(ymdtime);
          orderList[i].pay_time = ymdtime

          if (orderList[i].status===3) {
            orderList[i].status="待支付"
          }else if(orderList[i].status===2){
            orderList[i].status="已支付"
          }else if(orderList[i].status===1){
            orderList[i].status="已完成"
          }
        }
        // console.log(orderList)

        let totalPrice = 0 //总价
        for (let i = 0; i < orderList.length; i++) {
          for(let j = 0; j <orderList[i].menuOrder.length; j++){

          }
        }


        that.setData({
          orderList: orderList
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})